package adkr

import (
    "ebbflow/pkg/crypto"
    "fmt"
    "sync"
)

var (
    pkMu sync.RWMutex
    pkMap = make(map[int]*crypto.PaillierPublicKey)
    skMap = make(map[int]*crypto.PaillierPrivateKey)
)

// RegisterPaillierKeys registers a Paillier keypair for a process id.
func RegisterPaillierKeys(pid int, pk *crypto.PaillierPublicKey, sk *crypto.PaillierPrivateKey) {
    pkMu.Lock()
    defer pkMu.Unlock()
    pkMap[pid] = pk
    skMap[pid] = sk
}

// GetPaillierPK returns the public key for a process id.
func GetPaillierPK(pid int) (*crypto.PaillierPublicKey, error) {
    pkMu.RLock()
    defer pkMu.RUnlock()
    pk, ok := pkMap[pid]
    if !ok { return nil, fmt.Errorf("no Paillier PK for pid %d", pid) }
    return pk, nil
}

// GetPaillierSK returns the private key for a process id.
func GetPaillierSK(pid int) (*crypto.PaillierPrivateKey, error) {
    pkMu.RLock()
    defer pkMu.RUnlock()
    sk, ok := skMap[pid]
    if !ok { return nil, fmt.Errorf("no Paillier SK for pid %d", pid) }
    return sk, nil
}







